﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;  
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class web_Controls_ctrl_vl_top_login : System.Web.UI.UserControl
{
    public string sUser = "", sPass = "",mess="";
    Common comm = new Common();
	public Boolean kt=false;
    protected void Page_Load(object sender, EventArgs e)
    {
		if (Request.Url.AbsolutePath.Contains("web")) kt = true;
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        sUser = comm.TextFormat(txtUser.Text);
        sPass = comm.TextFormat(txtPass.Text);
        NhaTuyenDungCommon ntdComm = new NhaTuyenDungCommon();
        if (cbo.SelectedValue == "0")//Viec tim nguoi
        {
            if (ntdComm.login(sUser, sPass))
            {

                DataRow userdtr = comm.getDataTable("select * from doanhnghiep_doanh_nghiep where tai_khoan = '" + sUser + "' ").Rows[0];

                Session["NTDuser"] = "Y";
                Session["NTD_Active"] = userdtr["kich_hoat"];
                Session["NTDid"] = userdtr["ma_doanh_nghiep"];
                Session["NTDtenNTD"] = userdtr["ten_doanh_nghiep"];
                Session["NTDtaikhoan"] = userdtr["tai_khoan"];
            }
            if ((Session["NTDuser"] != null) && Session["NTDuser"].ToString().Equals("Y"))
            {
                Response.Redirect("~/web/pages/nhatuyendung_home.aspx");
            }
        }
        else if (cbo.SelectedValue == "1")
        {
            if (Session["NTV_user"] != null) { Session.Remove("NTV_user"); Session.Remove("sNTV"); }
            //Kiem tra user va mat khau
            mess = NguoiTimViecCommon.Login(txtUser.Text.Trim(), txtPass.Text.Trim());
            if (mess.Split('-').GetValue(0).ToString() == "ok")
            {
                Session.Add("NTV_user", txtUser.Text.Trim());
                Session.Add("NTV_id", mess.Split('-').GetValue(1).ToString().Trim());
                Session.Add("NTV_active", mess.Split('-').GetValue(2).ToString().Trim());
                    Response.Redirect("~/web/pages/nguoitimviec_quanly.aspx?page=home");
            }
        }
    }
    protected void btnReg_Click(object sender, EventArgs e)
    {
        
        if (cbo.SelectedValue == "0")//Viec tim nguoi
        {
            Response.Redirect("~/web/pages/dangkynhatuyendung.aspx");
        }
        else if (cbo.SelectedValue == "1")
        {
            Response.Redirect("~/web/pages/dangkynguoitimviec.aspx");
        }
    }
}
